package com.demo.reservation.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.reservation.domain.Userinfo;
import com.demo.reservation.mapper.UserinfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class UseinfoService extends ServiceImpl<UserinfoMapper, Userinfo> {
    public Userinfo create(Userinfo u) {
        Userinfo one = null;

        if (StringUtils.hasLength(u.getName())
                && StringUtils.hasLength(u.getPhone())) {
            QueryWrapper q = new QueryWrapper();
            q.eq("name", u.getName());
            q.eq("phone", u.getPhone());
            one = getOne(q);
        }
        if (null == one) {
            save(u);
            return u;
        }
        return one;
    }
}
